package com.sc.pattern.countdown;

/**
 * Created  on 2018/1/13.
 *
 * @author sc
 */
public class CountDown {
    private final int total;
    private int counter;


    public CountDown(int total) {
        this.total = total;
    }
    public void down(){
        synchronized (this){
            counter++;
            this.notifyAll();
        }
    }

    public void await() throws InterruptedException {
        synchronized (this){
            while (counter!=total){
                this.wait();
            }
        }
    }
}
